<style>
    .layui-form-label {
        width: 100px;
    }

    .layui-input-block {
        margin-left: 130px;
    }

    .tableSelectBar {
        width: 680px;
        margin-bottom: 10px;
    }

    .tableSelect .layui-table-view {
        margin-bottom: 10px !important;
    }
</style>
<div class="rightcontent rc-bg-grey">
    <div class="rc-pagepadding ">
        <div class=" rc-pannel layui-form">
            <div class=" rc-pannel-header rc-pagepadding rc-bold">
                <i class="iconfont goback rc-pointer">&#xe62b;</i> 编辑站点管理员
            </div>
            <div class="rc-pannel-body  rc-pagepadding">



                <div class="layui-form-item">
                    <label class="layui-form-label">选择用户</label>
                    <div class="layui-input-block">
                        <input type="text" id="seluser" readonly lay-verify="required" value="<?php echo $admininfo['username'] ?>" placeholder="请选择用户" autocomplete="off" class="layui-input">
                        <input type="hidden" name="uid" id="uid" value="<?php echo $admininfo['uid'] ?>" />

                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">绑定组织架构</label>
                    <div class="layui-input-block">
                        <?php echo element('organcascader', name: 'companyid', value: $admininfo['companyid']) ?>
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">选择角色</label>
                    <div class="layui-input-block">

                        <?php
                        $roleids = explode(',', trim($admininfo['roleids'], ','));
                        foreach ($roles as $role) {
                        ?>
                            <input type="checkbox" name="roleids[]" <?php echo in_array($role['id'], $roleids) ? 'checked' : '' ?> value="<?php echo $role['id'] ?>" title="<?php echo $role['title'] ?>" />

                        <?php
                        } ?>


                    </div>
                </div>


                <div class="layui-form-item rc-margin-bottom0">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="submit">提交</button>
                        <button type="reset" class="layui-btn layui-btn-sm">重置</button>
                    </div>
                </div>

            </div>



        </div>

    </div>
</div>
<script src="/static/admin/lib/layui/modules/tableSelect.js"></script>
<script>
    layui.use(function() {

        var form = layui.form;

        var tableSelect = layui.tableSelect;
        tableSelect.render({
            elem: '#seluser', //定义输入框input对象 必填
            checkedKey: 'id', //表格的唯一建值，非常重要，影响到选中状态 必填
            searchKey: 'searchkeyword', //搜索输入框的name值 默认keyword
            searchPlaceholder: '关键词搜索', //搜索输入框的提示文字 默认关键词搜索
            table: { //定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                url: '/admin/Admin/add?type=seluser',
                cols: [
                    [{
                            type: 'radio'
                        },
                        {
                            field: 'username',
                            title: '用户名'
                        }, {
                            field: 'phone',
                            title: '手机'
                        }
                    ]
                ],
                parseData: function(res) { // res 即为原始返回的数据
                    return {
                        "code": res.code, // 解析接口状态
                        "msg": res.message, // 解析提示文本
                        "count": res.data.total, // 解析数据长度
                        "data": res.data.item // 解析数据列表
                    };
                },
                request: {
                    limitName: 'pagesize' // 每页数据条数的参数名，默认：limit
                }
            },
            done: function(elem, data) {
                $('#seluser').val(data.data[0]['username']);
                $('#uid').val(data.data[0]['id']);
                $('#seluser').attr("ts-selected", data.data[0]['id']);
            }
        });




        form.on('submit(submit)', function(data) {

            var postdata = data.field;

            $.ajax({
                url: '/admin/Admin/edit?id=<?php echo request()->get('id') ?>', //请求路径
                type: "POST", //请求方式
                data: postdata, // 默认写法
                success: function(data) {
                    if (data.code == 0) {
                        toastr_success("编辑成功", function() {
                            window.location.href = '/admin/Admin/index';
                        });
                    } else {
                        toastr_error(data.message);
                    }
                },
                error: function() {

                },

            });
        });



    });
</script>